from os import system
word_list = ["monkey", "mouse", "camel"]

#TODO-1 - Randomly choose a word from the word_list and assign it to a variable called chosen_word.

#TODO-2 - Ask the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase.

#TODO-3 - Check if the letter the user guessed (guess) is one of the letters in the chosen_word.

import random
game_word = random.choice(word_list)

display = []
for i in range(len(game_word)):
    display.append("_")

def print_result():
    result = "||" + "||".join(display) + "||"
    print(result)

def change_display(positions):
    if len(positions) > 0:
        for pos in positions:
            display[pos] = game_word[pos]

life_counter = 6

def print_ascii_art():
    stages = ['''
  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|   |
      |
      |
=========''', '''
  +---+
  |   |
  O   |
  |   |
      |
      |
=========
''', '''
  +---+
  |   |
  O   |
      |
      |
      |
=========
''', '''
  +---+
  |   |
      |
      |
      |
      |
=========
''']
    print(stages[life_counter])

def check_letter(letter):
    right_letters = []
    for n in range(len(game_word)):
        if game_word[n] == letter:
            right_letters.append(n)
    return right_letters

def check_word():
    is_complete = True
    if "_" in display:
        is_complete = False
    return is_complete

inputed_letters = []
system('clear')
print_result()

while True:
    guess = input("Guess a letter: ").lower()
    system('clear')
    if guess not in inputed_letters:
        inputed_letters.append(guess)
        results = check_letter(guess)
        if len(results) > 0:
            change_display(results)
            print("Yes takaya bukva")
        else:
            life_counter -= 1
            print("No matches")
    else:
        print("This letter already opened. Try another one")

    print_result()
    print_ascii_art()

    if check_word():
        print("You are win!")
        break

    if life_counter < 1:
        print("You are dead")
        break
